package com.yunkaweilai.android.activity.recharge;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.yunkaweilai.android.R;
import com.yunkaweilai.android.base.BaseActivity;
import com.yunkaweilai.android.model.ShopRechargeInfoBean;
import com.yunkaweilai.android.utils.TitleBuilder;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2019/2/20.
 */

public class RechargeHuoDongActivity extends BaseActivity {

    @BindView(R.id.id_listview)
    ListView idListview;

    public static final String RECHARGE_TIME_LIST = "RECHARGE_TIME_LIST";
    public static final String RECHARGE_TYPE = "RECHARGE_TYPE";
    public static final String RECHARGE_ID = "RECHARGE_ID";
    public static final String RECHARGE_NAME = "RECHARGE_NAME";
    private List<ShopRechargeInfoBean.DataBean.ActivityListBean> list = new ArrayList<>();
    private String type;// 1 pc  2 app  3pad  4wechat
    private CommonAdapter<ShopRechargeInfoBean.DataBean.ActivityListBean> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.recharge_time_layout);
        ButterKnife.bind(this);
        new TitleBuilder(mAc).setTitleText("优惠活动")
                .setLeftImage(R.mipmap.ic_go_back)
                .setLeftOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
        type = getIntent().getStringExtra(RECHARGE_TYPE);
        List<ShopRechargeInfoBean.DataBean.ActivityListBean>activitylist = (List<ShopRechargeInfoBean.DataBean.ActivityListBean>) getIntent().getSerializableExtra(RECHARGE_TIME_LIST);
        ShopRechargeInfoBean.DataBean.ActivityListBean bean = new ShopRechargeInfoBean.DataBean.ActivityListBean();
        bean.setTitle("不使用优惠活动");
        bean.setId("");
        list.add(bean);
        list.addAll(activitylist);
        initAdapter();
        initClick();
    }

    private void initAdapter() {
        adapter = new CommonAdapter<ShopRechargeInfoBean.DataBean.ActivityListBean>(this,R.layout.item_list_company,list) {
            @Override
            protected void convert(ViewHolder viewHolder, ShopRechargeInfoBean.DataBean.ActivityListBean item, int position) {
                viewHolder.setText(R.id.id_tv_company,item.getTitle()+"");
            }
        };
        idListview.setAdapter(adapter);
    }

    private void initClick() {
        idListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();
                intent.putExtra(RECHARGE_ID,list.get(position).getId()+"");
                intent.putExtra(RECHARGE_NAME,list.get(position).getTitle()+"");
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }
}
